package com.example;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import org.springframework.core.io.ClassPathResource;

import java.util.ArrayList;
import java.util.List;

public class Rep {

    public static void main(String[] args) {
        //文件名称+路径 ExcelFileUtil.getPath()
        String templateFileName = "F://list.xlsx";
        //当前项目路径
        //String fileName = ExcelFileUtil.getPath() + "simpleFill" + System.currentTimeMillis() + ".xlsx"
        //生成的文件路径
        String fileName = "F://" + "listFill" + ".xlsx";
        //分多次填充 会使用文件缓存（省内存）
        ExcelWriter excelWriter = EasyExcel.write(fileName).withTemplate(templateFileName).build();
        WriteSheet writeSheet = EasyExcel.writerSheet().build();

        excelWriter.fill(data(), writeSheet);
        excelWriter.fill(data(), writeSheet);
        // 千万别忘记关闭流
        excelWriter.finish();
    }

    private static List<FillData> data() {
        List<FillData> list = new ArrayList<FillData>();
        for (int i = 0; i < 10; i++) {
            FillData fillData = new FillData();
            list.add(fillData);
            fillData.setName("张三");
            fillData.setNumber(5.2);
        }
        return list;
    }

}
